﻿// CDialogAddfriend.cpp: 实现文件
//

#include "stdafx.h"
#include "ChatSystemClient.h"
#include "CDialogAddfriend.h"
#include "afxdialogex.h"
#include"ChatMessage.h"
#include"TcpSvr.h"

// CDialogAddfriend 对话框

IMPLEMENT_DYNAMIC(CDialogAddfriend, CDialogEx)

CDialogAddfriend::CDialogAddfriend(int user_id, CWnd* pParent /*=nullptr*/)
	:user_id_(user_id)
	,CDialogEx(IDD_DIALOG2, pParent)
	, m_fri_telnum_(_T(""))
{

}

CDialogAddfriend::~CDialogAddfriend()
{
}

void CDialogAddfriend::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDITAddFriendNum, m_fri_telnum_);
}


BEGIN_MESSAGE_MAP(CDialogAddfriend, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTONADDFRIEND, &CDialogAddfriend::OnBnClickedButtonaddfriend)
END_MESSAGE_MAP()


// CDialogAddfriend 消息处理程序


void CDialogAddfriend::OnBnClickedButtonaddfriend()
{
	// TODO: 在此添加控件通知处理程序代码
	//1、获取输入框的内容
	UpdateData(TRUE);
	if (m_fri_telnum_.IsEmpty()) {
		MessageBox(TEXT("输入内容不能为空"));
		return;
	}
	//2、组织发送消息
	ChatMsg cm;
	cm._msg_type = AddFriend;
	//消息是谁发送的
	cm._user_id = user_id_;
	//消息内容
	cm._json_msg["telnum"] = m_fri_telnum_.GetString();
	std::string msg;
	cm.GetMsg(&msg);
	TcpSvr* ts = TcpSvr::getinstance();
	if (ts == NULL) {
		MessageBox("获取TCP服务失败，请重试");
		return;
	}
	//3、将这个消息发送出去
	ts->Send(msg);
	CDialog::OnCancel();
}
